Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
What does the .filter(i => i) do in this case?

I'm reading the process being built on

https://developers.cardano.org/docs/integrate-cardano/listening-for-payments-cli/#process-utxo-table

and I'm stuck on the results of this part:

// Calculate total lovelace of the UTXO(s) inside the wallet address
const utxoTableRows = rawUtxoTable.data.trim().split('\n');
let totalLovelaceRecv = 0;
let isPaymentComplete = false;

for (let x = 2; x < utxoTableRows.length; x++) {
    const cells = utxoTableRows[x].split(" ").filter(i => i);
    totalLovelaceRecv += parseInt(cells[2]);
}

I understand that up to the .split(" ") part, the table has been split into at least 2 items within the array of utxoTableRows since the first row the headers that we aren't interested in and the second row is the first utxo being processed. The .split(" ") then splits the row where there is a space but I don't know what the filter part does. The query utxo table looks as follows:

TxHash TxIx Amount
dfb99f8f103e56a856e04e087255dbaf402f3801acb71a6baf423a1054d3ccd5 0 1749651926

As you can see there are two rows. I'm completely lost at the filter component. I get more lost in the following command parseInt(cells[2]). I know somehow it takes the amount as a string and converts to integer. The [2] reference throws me off because wouldn't it have to be [3] since the amount is the 3rd item that gets split in that row? The only thing I can think of is that the .filter(i => i) throws out the TxHash, then saves the TxIx (in this case 0) in cell[1] and the amount (in this case 1749651926) in cell[2], both as strings.

Thank you for the help.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

filter will filter out all items in the array where the callback returns false after coercion.

In this case, the filter removes all blank strings in the array. If the item is an empty string, the callback returns false, since empty strings, when coerced to a boolean, are false (see: Falsy values).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda